import { defineStore } from 'pinia'
import {reactive} from 'vue'
import {
	USER_INFO,
	USER_INTEREST,
	USER_INTEREST_LIST,
	USER_REGISTER,
	UserList,
	request_get_user_detail,
	request_post_user_info,
	request_post_user_interest,
	request_post_user_interest_list,
	request_post_user_regiter,
	requestAdminUserList,
	requestAdminBasicUserDetail
} from '../service/user'

export default defineStore("user", () => {
	const userInfo = reactive({
		userInfos: {},
		adminUserInfos: {}
	})
	// 用户详情
	const getUserDetail = async () => {
		try {
			const data = await request_get_user_detail()
			userInfo.userInfos = data?.data
		} catch(e) {
			uni.showToast({
				title: '错误:' + e
			})
		}
	}
	
	// 携带userid访问
	const adminBasicUserDetail = async (id: number = 1) => {
		try {
			const data = await requestAdminBasicUserDetail(id)
			userInfo.adminUserInfos = data?.data
		} catch(e) {
			uni.showToast({
				title: '错误:' + e
			})
		}
	}
	// 获取用户列表-分页
	const adminUserList = async (userList: Partial<UserList>) => {
		const res = await requestAdminUserList(userList)
		console.log(res, "| res");
	}
	// 用户注册
	const userRegister = async (userRegister : USER_REGISTER) => {
		const res = await request_post_user_regiter(userRegister)
		return res
	}
	
	// 用户修改资料
	const saveUserInfo = async (userInfo : USER_INFO) => {
		const res = await request_post_user_info(userInfo)
		return res
	}
	
	// 关注用户
	const userInterest = async (userInterest : USER_INTEREST) => {
		const res = await request_post_user_interest(userInterest)
		console.log(res, "| res");
	}
	
	// 用户关注列表
	const userInterestList = async (userInterestList : USER_INTEREST_LIST) => {
		const res = await request_post_user_interest_list(userInterestList)
		console.log(res, "| res");
	}
	return { 
		userInfo,
		getUserDetail, 
		saveUserInfo, 
		userInterest,
		userInterestList,
		userRegister,
		adminBasicUserDetail
	}
})